Skip to content

preserve daemon sessions across self-updates - #369

Merged
kevinjosethomas merged 16 commits into
mainfrom
fix/update-daemon-session-restore
Jul 10, 2026
Merged

preserve daemon sessions across self-updates#369
kevinjosethomas merged 16 commits into
mainfrom
fix/update-daemon-session-restore

Conversation

@kevinjosethomas

@kevinjosethomas kevinjosethomas commented Jul 10, 2026

Copy link
Copy Markdown
Member
  • self-updates no longer lose restored sessions when old and replacement daemons overlap during socket cleanup.
  • open session windows and the agents view now reconnect automatically after the daemon restarts.
  • added regression coverage for socket ownership races and update-session reattachment.

Note

Medium Risk
Touches core daemon lifecycle, socket ownership, and client reconnect paths where races could still affect session restore or stale socket handling; behavior is heavily tested but production update flows are critical.

Overview
Self-updates should no longer drop attached sessions when old and replacement daemons overlap during Unix socket cleanup. Shutdown now broadcasts daemon_closing with reason update or shutdown, and clients use that signal instead of guessing from a bare socket close.

DaemonAgentConnection automatically reconnects after an update restart: it re-lists sessions, re-attaches by session file/id, and emits session_replaced on success. Failures surface guided errors (session id, file path, daemon log) instead of raw protocol reasons. AgentsViewMode reconnects and refreshes on restarts but stops retrying after an intentional shutdown with sticky restart guidance.

Socket lifecycle is hardened with proper-lockfile, inode-based identity checks, a post-shutdown cleanup grace, and shutdownDaemonAndWait treating accepted shutdowns as gone only after the socket is reclaimable (including crash-left stale sockets).

A small generate-models tweak refreshes Prime Inference alias contextWindow / maxTokens from the live catalog when merging snapshot models.

Reviewed by Cursor Bugbot for commit 4d309ba. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Preserve daemon sessions across self-updates by reconnecting and restoring active sessions

  • When a daemon restarts for a self-update, DaemonAgentConnection now automatically reconnects the transport and re-attaches to the previous session, emitting a session_replaced event on success and a terminal closed event with recovery guidance after a 120s timeout.
  • The daemon broadcasts a new daemon_closing outbound message (with reason 'update' or 'shutdown') before closing, allowing clients to distinguish intentional shutdowns from crashes.
  • DaemonSocketClosedError carries the close reason through the error chain so callers can gate reconnection logic on getDaemonSocketCloseReason().
  • Agents View (AgentsViewMode) now auto-reconnects to the daemon for up to 120s on disconnection; on a clean 'shutdown' reason it stops retrying, shows a sticky error, and clears the session list.
  • Socket cleanup in daemon-socket.ts is now lock-coordinated and identity-checked to avoid unlinking a replacement daemon's socket during concurrent restarts.
  • Behavioral Change: closed events from DaemonAgentConnection now carry formatted user-facing messages with session ID, file, and diagnostic log path instead of raw protocol reasons.

Macroscope summarized 4d309ba.

Comment thread packages/coding-agent/src/modes/agents-view/agents-view-mode.ts
Comment thread packages/coding-agent/src/cli/daemon-launch.ts
Comment thread packages/coding-agent/src/modes/agents-view/agents-view-mode.ts
Comment thread packages/coding-agent/src/modes/daemon/daemon-socket.ts
Comment thread packages/coding-agent/src/modes/agents-view/agents-view-mode.ts
Comment thread packages/coding-agent/src/modes/daemon/daemon-socket.ts
Comment thread packages/coding-agent/src/modes/daemon/daemon-socket.ts
Comment thread packages/coding-agent/src/modes/agents-view/agents-view-mode.ts
Comment thread packages/coding-agent/src/modes/agents-view/agents-view-mode.ts
Comment thread packages/coding-agent/src/modes/agents-view/agents-view-mode.ts
Comment thread packages/coding-agent/src/modes/agent-connection/daemon-agent-connection.ts Outdated
Comment thread packages/coding-agent/src/modes/agents-view/agents-view-mode.ts Outdated
Comment thread packages/coding-agent/src/modes/daemon/daemon-mode.ts
Comment thread packages/coding-agent/src/modes/agents-view/agents-view-mode.ts

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 6c9bc9c. Configure here.

Comment thread packages/coding-agent/src/modes/agent-connection/daemon-agent-connection.ts Outdated
@kevinjosethomas
kevinjosethomas merged commit 4615258 into main Jul 10, 2026
3 of 4 checks passed
@kevinjosethomas
kevinjosethomas deleted the fix/update-daemon-session-restore branch July 16, 2026 23:51
zhengr pushed a commit to zhengr/prime-agent that referenced this pull request Aug 8, 2026
* fix(coding-agent): preserve daemon sessions across updates

* fix(coding-agent): address update restart review feedback

* fix(coding-agent): bound agents view reconnect cycles

* fix(coding-agent): harden daemon reconnect edge cases

* fix(coding-agent): refresh restored session identity

* fix(coding-agent): start update reconnect immediately

* fix(coding-agent): recover unannounced update closes

* fix(coding-agent): cancel update restore on dispose

* fix(coding-agent): preserve explicit daemon shutdown

* fix(coding-agent): drop stale update transport

* fix(coding-agent): guard update reconnect reentrancy

* fix(coding-agent): coordinate shared update reconnect

* fix(coding-agent): explain daemon connection failures

* fix(coding-agent): coordinate daemon close recovery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant